#ifndef CONTEXT_H
#define CONTEXT_H

#include <QtCore>

#include <defs/global.h>
#include <core/entityobject.h>
#include <QtDeclarative>
#include <QSharedPointer>
#include <QPointer>
#include <config/config.h>

namespace Opl {
    namespace Scripting {
        class ScriptEnvironment;
    };

    namespace Core {
        class Task;
    }
};

namespace Optra {

    namespace Extensions{

        class ZoneInterface;
        class MainWindow;
        class Plugin;

        O_PRIVATE_DECLARE(Context);
        class EXTENSIONS_EXPORT Context : public Opl::Core::EntityObject {
            Q_OBJECT
            Q_PROPERTY(Opl::Core::EntityObject* bridge READ bridge)
            //Q_PROPERTY(ZoneInterface* interface READ interface);
            Q_PROPERTY(QDir rootDir READ rootDir)
            Q_PROPERTY(QString binDir READ binDir)
            Q_PROPERTY(QString resourcesDir READ resourcesDir)
            Q_PROPERTY(QString configDir READ configDir)
            Q_PROPERTY(QString userDir READ userDir)
            //Q_PROPERTY(QVariant globalConfig READ globalConfig);
            //Q_PROPERTY(QVariant userConfig READ userConfig);
        public:
            Context(Opl::Core::EntityObject *parent = 0);
            Context(ZoneInterface* inf, Opl::Core::EntityObject *parent = 0);
            virtual ~Context();

            QDir rootDir()const;
            void setRootDir(const QDir& dir);

            QString binDir()const;
            void setBinDir(const QDir& dir);

            QString resourcesDir()const;
            void setResourcesDir(const QDir& dir);

            QString configDir()const;
            void setConfigDir(const QDir& dir);

            QString userDir()const;
            void setUserDir(const QDir& dir);

            Opl::Core::IConfig* config()const;
            void setConfig(Opl::Core::IConfig* cfg);

            Opl::Core::EntityObject* bridge()const;
            void setBridge(Opl::Core::EntityObject* b);

            ZoneInterface* inf()const;
            void setInterface(ZoneInterface* inf);

            virtual Optra::Extensions::Plugin* loadPlugin(const QString file) = 0;

            virtual void registerWindow(MainWindow* wnd) = 0;
            virtual Opl::Scripting::ScriptEnvironment* scripts() = 0;

            virtual bool start(Opl::Core::Task* task, QString name = QString()) = 0;
            virtual bool start(Opl::Core::Task* task, bool autodelete, QString name = QString()) = 0;



            virtual void process(const QDir& root, bool createIfNeeded = false) = 0;
            virtual QString toString();
        private:
            O_PRIVATE_DECLARE_MEMBER(Context)
        };

        typedef QPointer<Context> ContextPtr;
        //class ContextPtr : public QPointer<Context> {};

    }}
QML_DECLARE_INTERFACE(Optra::Extensions::Context)
#endif // CONTEXT_H

